unit OrderRpt;

interface

uses SysUtils, Windows, Messages, Classes, Graphics, Controls,
  StdCtrls, ExtCtrls, Forms, Quickrpt, QRCtrls, patterns;

type
  TOrdersByDateReport = class(TQuickRep)
  private

  public

  end;

  TControllerOrderReport = class(TController)
  private
    procedure PrintOrderReport(Preview: Boolean);
  protected
    procedure DoCommand(Command: string; const args: string=''); override;
  end;


var
  OrdersByDateReport: TOrdersByDateReport;

implementation
uses DataMod, QryCust, commandlist;
{$R *.DFM}


procedure TControllerOrderReport.DoCommand(Command: string; const args: string='');
begin
  if command = CMD_RPT_ORDER then
  begin
    PrintOrderReport(lowercase(args) = 'preview');
  end;
end;

procedure TControllerOrderReport.PrintOrderReport(Preview: Boolean);
const
  FromToHeading = 'From ''%s'' To ''%s''';
begin
  // Request the 'From' and 'To' dates from the user.
  with TQueryCustDlg.Create(nil) do
  begin
    MsgLab.Caption := 'Print all orders ranging:';
    if FromDate = 0 then FromDate := EncodeDate(95, 01, 01);
    if ToDate = 0 then ToDate := Now;

    if ShowModal = mrOk then
      with TMastData.GetInstance.OrdersByDateQuery do
      begin
        Close;
        PArams.ParamByName('FromDate').AsDate := FromDate;
        PArams.ParamByName('ToDate').AsDate := ToDate;
        Open;

      // Format the From To header with the user's dates entered
//        OrdersByDateReport.FromToHeading.Caption :=
//          Format(FromToHeading, [DateToStr(FromDate), DateToStr(ToDate)]);

        if Preview then
          OrdersByDateReport.Preview
        else
          OrdersByDateReport.Print;
        Close;
      end;
    free;
  end;
end;


{//disable
initialization
  ControlCenter.RegController(TControllerOrderReport.Create);
  OrdersByDateReport := TOrdersByDateReport.create(application);
}

end.

